package com.ruoyi.apps.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.apps.domain.AntApps;
import com.ruoyi.apps.service.IAntAppsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 应用管理Controller
 * 
 * @author ruoyi
 * @date 2023-01-15
 */
@Controller
@RequestMapping("/apps/apps")
public class AntAppsController extends BaseController
{
    private String prefix = "apps/apps";

    @Autowired
    private IAntAppsService antAppsService;

    @RequiresPermissions("apps:apps:view")
    @GetMapping()
    public String apps()
    {
        return prefix + "/apps";
    }

    /**
     * 查询应用管理列表
     */
    @RequiresPermissions("apps:apps:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AntApps antApps)
    {
        startPage();
        List<AntApps> list = antAppsService.selectAntAppsList(antApps);
        return getDataTable(list);
    }

    /**
     * 导出应用管理列表
     */
    @RequiresPermissions("apps:apps:export")
    @Log(title = "应用管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AntApps antApps)
    {
        List<AntApps> list = antAppsService.selectAntAppsList(antApps);
        ExcelUtil<AntApps> util = new ExcelUtil<AntApps>(AntApps.class);
        return util.exportExcel(list, "应用管理数据");
    }

    /**
     * 新增应用管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存应用管理
     */
    @RequiresPermissions("apps:apps:add")
    @Log(title = "应用管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AntApps antApps)
    {
        return toAjax(antAppsService.insertAntApps(antApps));
    }

    /**
     * 修改应用管理
     */
    @RequiresPermissions("apps:apps:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AntApps antApps = antAppsService.selectAntAppsById(id);
        mmap.put("antApps", antApps);
        return prefix + "/edit";
    }

    /**
     * 修改保存应用管理
     */
    @RequiresPermissions("apps:apps:edit")
    @Log(title = "应用管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AntApps antApps)
    {
        return toAjax(antAppsService.updateAntApps(antApps));
    }

    /**
     * 删除应用管理
     */
    @RequiresPermissions("apps:apps:remove")
    @Log(title = "应用管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(antAppsService.deleteAntAppsByIds(ids));
    }
}
